package main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by arianne on 2014-07-13.
 */
public class InputHelper {
    public Integer getUserInput(String prompt) {
        String inputLine = null;
        System.out.print(prompt + " ");

        try {
            BufferedReader is = new BufferedReader(
                    new InputStreamReader(System.in)
            );
            inputLine = is.readLine();
            if (inputLine.length() == 0) return null;
        } catch (IOException e) {
            System.out.println("IOException: " + e);
        }

        Integer inputAsInt;
        try {
            inputAsInt = Integer.parseInt(inputLine);
        } catch (NumberFormatException e) {
            return null;
        }

        if(inputAsInt < 0) {
            return null;
        }
        return inputAsInt;
    }
}
